﻿/*
=======================================================
    ChangeWirerope【换绳】
=======================================================
*/

namespace Services
{
    public interface IChangeWireropeRepository : IRepository<ChangeWirerope>
    {
        void InsertForAdmin(ChangeWirerope changeWirerope, Bill bill, BillDetail billDetail, UsingWirerope usingWirerope, UsingWirerope oldInfo, Stock stockInfo);
    }


    public class ChangeWireropeRepository : BaseRepository<ChangeWirerope>, IChangeWireropeRepository
    {
        public ChangeWireropeRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<ChangeWirerope> query)
            : base(dB, currentUser, query)
        {
        }

        #region InsertForAdmin
        public void InsertForAdmin(ChangeWirerope changeWirerope, Bill bill, BillDetail billDetail, UsingWirerope usingWirerope, UsingWirerope oldInfo, Stock stockInfo)
        {
            var billID = _DB.Insertable(bill).ExecuteReturnIdentity();

            billDetail.BillID = billID;


            _DB.Insertable(billDetail).ExecuteCommand();

            var id = _DB.Insertable(usingWirerope).ExecuteReturnIdentity();

            changeWirerope.NewUsingWireropeID = id;

            Insert(changeWirerope);

            _DB.Updateable(oldInfo).ExecuteCommand();

            _DB.Updateable(stockInfo).ExecuteCommand();
        }
        #endregion
    }
}
